<?php
//   include_once $_SERVER['DOCUMENT_ROOT'].'/PariGest/pages/inc/entete.php';
require_once $REP_CLASS . 'class.Compte.php';
require_once $REP_CLASS . 'class.Pari.php';
require_once $REP_CLASS . 'class.Operation.php';

try
{
  $compte    = new Compte($db);
  $pari      = new Pari($db);
  $operation = new Operation($db);

  $idCompte = "0";
  if( isset($_COOKIE[Compte::$ID_COMPTE_SESSION]) )
  $idCompte = $_COOKIE[Compte::$ID_COMPTE_SESSION];

  $compte->setIdCompte($idCompte);
  $compte->affichage();
  
  $benefDuMois      = $pari->selectBeneficeDuMois($idCompte);
  $benefTotal       = $pari->selectBenefice($idCompte);
  $perteMois        = $pari->selectPerteDuMois($idCompte);
  $perteTotal       = $pari->selectPerte($idCompte);
  $nbParisMois      = $pari->selectNbParisOfMois($idCompte);
  $nbParis          = $pari->selectNbParis($idCompte);
  $benefMoisPrCent  = 0;
  $benefTotalPrCent = 0;
  $perteMoisPrCent  = 0;
  $perteTotalPrCent = 0;
  if( ($benefDuMois + $perteMois) > 0 )
  {
    $benefMoisPrCent  = round($benefDuMois * 100 / ($benefDuMois + $perteMois), 2);
    $perteMoisPrCent  = round($perteMois * 100   / ($benefDuMois + $perteMois), 2);
  }
  
  if( ($benefTotal + $perteTotal) > 0 )
  {
    $benefTotalPrCent = round($benefTotal * 100 / ($benefTotal + $perteTotal), 2);
    $perteTotalPrCent = round($perteTotal * 100 / ($benefTotal + $perteTotal), 2);
  }
  
  $smarty->assign('Solde',           $compte->getSolde());
  $smarty->assign('SoldeMois',       $operation->selectMontantParisDuMoisEnCours($idCompte));
  $smarty->assign('NbParisMois',     $nbParisMois);
  $smarty->assign('NbParis',         $nbParis);
  $smarty->assign('BenefMois',       $benefDuMois);
  $smarty->assign('BenefMoisPrCent', $benefMoisPrCent);
  $smarty->assign('BenefTotal',      $benefTotal);
  $smarty->assign('BenefTotalPrCent',$benefTotalPrCent);
  $smarty->assign('PerteMois',       $perteMois);
  $smarty->assign('PerteMoisPrCent', $perteMoisPrCent);
  $smarty->assign('PerteTotal',      $perteTotal);
  $smarty->assign('PerteTotalPrCent',$perteTotalPrCent);
  
  
//   $smarty->assign('PerteTotal', $pari->selectBeneficeDuMois($idCompte));
  
//   $smarty->assign('LstParis', $stmt->fetchAll());
//   $smarty->assign('NbParis', $stmt->rowCount());
}
catch(MyException $e)
{
  $trace->fb('!!!!! ERREUR !!!!!');
  include $_SERVER['DOCUMENT_ROOT'].'/PariGest/pages/inc/catch.php';
}
//   $smarty->display('Compte.tpl');
?>
